import produce from 'immer';
import {Action, Channel, TimeMeta} from 'types';

export interface QueryState {
  channels?: Channel[]; // 渠道
  selectdChannel: Channel; // 选中渠道Id
  queryTimes?: TimeMeta;
}
export const initialState: Readonly<QueryState> = {
  channels: [],
  selectdChannel: {id: '', name: ''},
  queryTimes: undefined,
};

export default (originalState = initialState, action: Action) =>
  produce(originalState, (state) => {
    switch (action.type) {
      case 'setChannels':
        state.channels = action.payload;
        return;
      case 'setSelectedChannel':
        state.selectdChannel = action.payload;
        return;
      case 'setSelectedDate':
        state.queryTimes = action.payload;
        return;
    }
  });
